
import java.awt.Container;
import java.awt.TextArea;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.AbstractAction;
import javax.swing.ActionMap;
import javax.swing.InputMap;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JSplitPane;
import javax.swing.KeyStroke;

/**
 *
 * @author David Rodriguez A.
 */

public class AppValveViewer extends JFrame implements KeyListener {
    JLabel status, temp, value, name, calling, SYSevents;
    JProgressBar pb;
    JSplitPane split;
    TextArea textarea;
    private int id_valve=0;
    private boolean overheating = false; 
    
    /**
     * Constructor
     */
    @SuppressWarnings("serial")
	public AppValveViewer(){
        super("AppValveViewer ... ");           //nombre aplicación
        setTitle("Reactor Status Monitor");     //nombre ventana
        setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); //seteando tamaño de ventana

        name = new JLabel("ID Reactor: "+String.valueOf(id_valve));
        status = new JLabel("Status:");
        temp = new JLabel("T°: ");
        calling = new JLabel("a");
        SYSevents = new JLabel("System Events");
        
        String value_s = "0";
        //creando barra de progreso
        pb = new JProgressBar(0, 100); //rango de valores del grafico
        pb.setValue(0); //valor inicial del grafico
        pb.setStringPainted(true); //para que muestre el % desplegado
        pb.setString(value_s);

        //Posicion y elementos del panel========================================
        JPanel panel = new JPanel();
        panel.setLayout(null);
        panel.add(status); //agrega el string status
        status.setBounds (10,10,60,20);
        panel.add(name);//agrega el string id reactor con su respectivo id
        name.setBounds(70,30,150,20);
        panel.add(temp); //agrega el string T para la temperatura
        temp.setBounds(90,60,40,20);
        panel.add(pb);//agrega el progressbar
        pb.setBounds(120, 60, 320, 20);
        
        panel.add(calling);
        calling.setBounds(180, 60, 320, 20);

        JPanel console = new JPanel();
        console.setLayout(null);
        console.add(SYSevents);
        SYSevents.setBounds(220, 0, 320, 20);

        textarea = new TextArea("", 1024, 1024);
        console.add(textarea);
        textarea.setBounds(20,40, 480, 190);
        textarea.setEditable(false);
        
        JSplitPane splited = new JSplitPane(JSplitPane.VERTICAL_SPLIT,true,panel,console);
        splited.setDividerLocation(120);
        splited.setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
        Container contentPane = getContentPane();
        contentPane.add(splited);
        // No se sabe con certeza que componente tiene el foco
        textarea.addKeyListener(this);
        pb.addKeyListener(this);
        console.addKeyListener(this);
        panel.addKeyListener(this);
        //======================================================================
    }
    public boolean getTempMode(){
    	return overheating;
    }

    /**
     * 
     * @param temp
     * @param value
     */
    public void setLabel(int temp, int value){
        String t= String.valueOf(temp);
        String v= String.valueOf(value);
        this.temp.setName(t);
        this.value.setName(v);
    }
    public void setArea(String s){
        this.textarea.append(s);
    }
    /**
     *
     * @param id
     */
    public void setIdvalve(int id){
        this.id_valve = id;
        name.setText("ID Reactor: "+String.valueOf(id));
    }
    
    /**
     *
     * @param value
     */
    public void setProgressValue(int value){
        this.pb.setValue(value);
        this.pb.setString(String.valueOf(value)+"°");
    }
    public static final int DEFAULT_WIDTH = 520;
    public static final int DEFAULT_HEIGHT = 400;

	@Override
	public void keyPressed(KeyEvent e) {
	}
	@Override
	public void keyReleased(KeyEvent e) {
		// TODO Auto-generated method stub
		if (e.getKeyChar() == KeyEvent.VK_D)
			overheating = true;
		else if (e.getKeyChar() == KeyEvent.VK_F) 
			overheating = false;
	}
	@Override
	public void keyTyped(KeyEvent e) {
	}
}
